package com.zuosh.netty5;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * Created by kai on 2015/12/21 0021.
 */
public class myDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("msg will be decode ...");
        byte[] bb = new byte[in.readableBytes()];
        in.readBytes(bb);
        out.add(new String(bb));
    }

//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        System.out.println("myDecoder##channel read...");
//        ctx.fireChannelRead(msg);
//    }

//    @Override
//    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
//        System.out.println("myDecoder##write ...");
//        ctx.fireChannelRead(msg);
//    }

//    @Override
//    public void read(ChannelHandlerContext ctx) throws Exception {
//        System.out.println("myDecoder#read ...");
//        ctx.fireChannelRead(ctx);
//    }
}
